<?php
/**
 * Created by PhpStorm.
 * User: root
 * Date: 18-8-29
 * Time: 上午10:16
 */

namespace apps\httpd\models;


use mix\validators\Validator;

class UeditorForm extends Validator
{
    public $max_size;
    public $fieldName;
    public $upfile;
    public $source;

    public function __Construct($max_size,$fieldName)
    {

        $this->max_size = $max_size;
        $this->fieldName = $fieldName;
    }

    public function rules()
    {
        return [
//            提交的图片表单名称imageFieldName,scrawlFieldName,videoFieldName,fileFieldName
            'upfile' => ['file', 'mimes' => ['image/gif', 'image/jpeg', 'image/png','image/bmp',
                'application/x-shockwave-flash','video/x-msvideo','video/mpeg',
                'video/quicktime','audio/mpeg','audio/x-wav','audio/mid',
                'application/x-compress','application/x-gzip','application/x-tar','application/zip',
                'application/msword','application/pdf','application/vnd.ms-excel','application/vnd.ms-powerpoint',
                'text/plain',
                'audio/mp3', 'video/mp4'], 'maxSize' => 1024 * 1000],

//            抓取远程图片配置
            'source' => ['image', 'mimes' => ['image/gif', 'image/jpeg', 'image/png','image/bmp'], 'maxSize' => 1024 * 100],
        ];
    }

    public function scenarios()
    {
        return [
            'upfile'=>['required'=>['upfile']],
            'source'=>['required'=>['source']],
        ];
    }

    public function messages()
    {
        return [
            'upfile.required' =>'upfile字段必须',
            'upfile.file'=>'upfile必须是文件格式',
            'upfile.mimes'=>'upfile的mimes类型要匹配',
            'upfile.maxSize'=>'upfile不能超过最大',
            'source.required' =>'source字段必须',
            'source.image'=>'image必须是图片格式',
            'source.mimes'=>'image的mimes类型要匹配',
            'image.maxSize'=>'image不能超过最大',

        ];
    }

}
